package com.situ.feemanagement.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.feemanagement.mapper.AuthMapper;
import com.situ.feemanagement.pojo.Auth;
import com.situ.feemanagement.pojo.query.AuthQuery;
import com.situ.feemanagement.service.IAuthService;
import com.situ.feemanagement.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthServiceImpl implements IAuthService {

    @Autowired
    private AuthMapper authMapper;

    @Override
    public PageResult<Auth> selectByPage(AuthQuery authQuery) {
        PageHelper.startPage(authQuery.getPage(), authQuery.getLimit());
        List<Auth> list = authMapper.selectByPage(authQuery);
        PageInfo<Auth> pageInfo = new PageInfo<>(list);
        int totalCount = (int) pageInfo.getTotal();
        return new PageResult<>(0, "", totalCount, list);
    }

    @Override
    public void deleteById(int id) {
        authMapper.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        for (String id : ids) {
            authMapper.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Auth auth) {
        authMapper.add(auth);
    }

    @Override
    public Auth selectById(int id) {
        return authMapper.selectById(id);
    }

    @Override
    public void Update(Auth auth) {
        authMapper.update(auth);
    }

    @Override
    public void updateStatus(int id, int status) {
        authMapper.updateStatus(id, status);
    }

    @Override
    public List<Auth> selectByRole(Integer role) {
        return authMapper.selectByRole(role);
    }
}
